package vip.xiaonuo.smzq.modular.dictionary.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.smzq.core.gson.GsonUtil;
import vip.xiaonuo.smzq.core.tools.excel.ExcelImportUtil;
import vip.xiaonuo.smzq.modular.dictionary.entity.Cb13Zycllx;
import vip.xiaonuo.smzq.modular.dictionary.entity.excelEnt.Cb13ZycllxExc;
import vip.xiaonuo.smzq.modular.dictionary.service.ICb13ZycllxService;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


/**
 * 资源储量类型
 *
 * @author eomer
 * @since 2024-02-21
 */
@Api(tags = "资源储量类型")
@RestController
@RequestMapping("/dictionary/cb13Zycllx")
@Validated
public class Cb13ZycllxController {

    @Resource
    private ICb13ZycllxService iCb13ZycllxService;

    /**
     * 添加资源储量类型
     */
    @ApiOperation("添加资源储量类型")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid Cb13Zycllx cb13Zycllx) {
        iCb13ZycllxService.save(cb13Zycllx);
        return CommonResult.ok();
    }

    /**
     * 删除资源储量类型
     */
    @ApiOperation("删除资源储量类型")
    @PostMapping("/delete")
    public CommonResult<String> delete(@ApiParam(name = "pkid", value = "主键") @RequestParam String pkid) {
        iCb13ZycllxService.removeById(pkid);
        return CommonResult.ok();
    }

    /**
     * 编辑资源储量类型
     */
    @ApiOperation("编辑资源储量类型")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid Cb13Zycllx cb13Zycllx) {
        iCb13ZycllxService.updateById(cb13Zycllx);
        return CommonResult.ok();
    }

    /**
     * 资源储量类型分页查询
     */
    @ApiOperation("资源储量类型分页查询")
    @GetMapping("/list")
    public CommonResult<List<Cb13Zycllx>> page() {
        return CommonResult.data(iCb13ZycllxService.getList());
    }

    /**
     * 导入
     */
    @ApiOperation("导入")
    @PostMapping("/import")
    public CommonResult<String> importExcel(@RequestParam("file") MultipartFile file) {
        try {
            List<Cb13ZycllxExc> list = ExcelImportUtil.readMultipartFile(file, Cb13ZycllxExc.class);
            List<Cb13Zycllx> cb01Zhs = GsonUtil.ObjectToList(list, Cb13Zycllx.class);
            iCb13ZycllxService.saveBatch(cb01Zhs);
            return CommonResult.ok();
        } catch (Exception e) {
            return CommonResult.error(e.getMessage());
        }
    }
}
